package com.atguigu.springcloud.alibaba;

import java.util.concurrent.CompletableFuture;

/**
 *
 */
public class CompletableFutureInAction4 {

    public static void main(String[] args) throws InterruptedException {

        /*CompletableFuture.supplyAsync(() -> 1)
                .thenApply(i -> Integer.sum(i, 10))
                .whenComplete((v, t) -> System.out.println(v));*/

/*        CompletableFuture.supplyAsync(() -> 1)
                .handle((v, t) -> Integer.sum(v, 10)) //handle 处理 ->结果增加10
                .whenComplete((v, t) -> System.out.println(v)) //
                .thenRun(System.out::println);*/ //输入没有结果
/*
        CompletableFuture.supplyAsync(() -> 1)
                .thenApply(i -> Integer.sum(i, 10)) //thenApply
                .thenAccept(System.out::println);*/ //thenAccept 没有结果返回值
/*
        CompletableFuture.supplyAsync(() -> 1)
                .thenCompose(i -> CompletableFuture.supplyAsync(() -> 10 * i)) //thenCompose
                .thenAccept(System.out::println);*/

/*        CompletableFuture.supplyAsync(() -> 1)
                .thenCombine(CompletableFuture.supplyAsync(() -> 2.0d), (r1, r2) -> r1 + r2) //输入和输出 结果合并
                .thenAccept(System.out::println);*/ //thenAccept 无返回值

        CompletableFuture.supplyAsync(() -> 1)
                .thenAcceptBoth(CompletableFuture.supplyAsync(() -> 2.0d), (r1, r2) -> {
                    System.out.println(r1);
                    System.out.println(r2);
                    System.out.println(r1 + r2);
                });

        Thread.sleep(1000L);
    }
}
